<template>
	<view class="page-body">
		<u-notice-bar mode="horizontal" :list="noticeList"></u-notice-bar>
		<view class="list-cell b-b " @click="showReportType=true">
			<text class="cell-tit">举报类型</text>
			<view class="fr color-94 fs30">
				{{reportTypeText}}
				<u-icon name="arrow-right"></u-icon>
			</view>
		</view>
		<u-select :default-value="defautlReportType" v-model="showReportType" :list="reportTypelist" @confirm="confirmReportType"></u-select>
		<view class="list-cell b-b " @click="showReportUser=true">
			<text class="cell-tit">被举报人</text>
			<view class="fr color-94 fs30">
				{{reportUserText}}
				<u-icon name="arrow-right"></u-icon>
			</view>
		</view>
		<u-select :default-value="defautlReportUser" v-model="showReportUser" :list="reportUserlist" @confirm="confirmReportUser"></u-select>
		<view class="list-cell mt20 block">
			<view class="cell-tit">相关证据</view>
			<view class="mt20 ">
				<u-upload ref="uUpload" @on-change="uploaded" @on-remove="removeImg" :action="upAction" max-count="6"></u-upload>
			</view>
		</view>
		<view class="list-cell mt20 block">
			<view class="cell-tit">详细描述</view>
			<view class="mt20 ">
				<u-input v-model="model.description" type="textarea" placeholder="请填写您的详细描述" :custom-style="{'background-color':'#EBEEF5','padding':'20rpx'}" />
			</view>
		</view>
		<view class="p20 mt50">
			<u-button size="default" shape="circle" :loading="isLoading" type="primary" @click="post">提交</u-button>
			<view class="text-center mt60 primary" @click="app.goPage('myReport')">我的举报</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			let that = this;
			return {
				isLoading: false,
				noticeList: ['需要实名举报，公司承诺对您的信息进去安全保护'],
				model: {
					report_type: 0,
					report_uid: 0,
					description: '',
					fileList: []
				},
				showReportType: false,
				reportTypelist: [],
				reportTypeText: '请选择举报类型',
				defautlReportType: [0],
				showReportUser: false,
				reportUserlist: [],
				reportUserText: '请选择被举报人',
				defautlReportUser: [0],
				upAction: this.config.upImageUrl,
				description: ''
			}
		},
		onLoad() {
			let that = this;
			//获取举报基础信息
			this.$u.post('channel/api.report/getBaseInfo').then(res => {
				Object.keys(res.data.reportType).forEach(function(key) {
					let data = {};
					data.value = key;
					data.label = res.data.reportType[key];
					that.reportTypelist.push(data);
				})
				Object.keys(res.data.sameLevelUser).forEach(function(key) {
					let data = {};
					data.value = res.data.sameLevelUser[key].user_id;
					data.label = res.data.sameLevelUser[key].user_id + ' - '+ res.data.sameLevelUser[key].real_name;
					that.reportUserlist.push(data);
				})
			});
		},
		onShow() {

		},
		computed: {},
		onReady() {},
		methods: {
			//确定选择举报类型
			confirmReportType(e) {
				this.reportTypeText = e[0].label;
				this.model.report_type = e[0].value;
				
			},
			//确定选择被举报人
			confirmReportUser(e) {
				this.reportUserText = e[0].label;
				this.model.report_uid = e[0].value;
			},
			uploaded(res, index, lists) {
				var res = JSON.parse(res.data);
				this.model.fileList.push(res.file);
			},
			removeImg(index, lists) {
				let file = this.model.fileList[index];
				this.model.fileList.splice(index, 1);
				this.$u.post(this.config.removeImageUrl, {
					file: file
				}).then(res => {})
			},
			//提交举报
			post() {
				if (this.isLoading == true) {
					return false;
				}
				if (this.model.report_type < 1) {
					return this.$u.toast('请选择举报类型.');
				}
				if (this.model.report_uid < 1) {
					return this.$u.toast('请选择被举报人.');
				}
				if (this.model.fileList.length < 1) {
					return this.$u.toast('请上传相关证据图片.');
				}
				if (this.model.description.length < 1) {
					return this.$u.toast('请填写您的详细描述.');
				}
				let data = {};
				data.report_type = this.model.report_type;
				data.report_uid = this.model.report_uid;
				data.description = this.model.description;
				data.fileList = this.model.fileList.join(',');
				this.isLoading = true;
				this.$u.post('channel/api.report/post', data).then(res => {
					uni.showModal({
						title: '提示',
						content: '提交成功，等待审核.',
						showCancel: false,
						success: function(res) {
							if (res.confirm) {
								uni.redirectTo({
								    url: 'myReport'
								});
							}
						}
					})
				}).catch(res => {
					this.isLoading = false;
				})
			}
		}
	}
</script>

<style>

</style>
